<template>
  <div class="">
    <el-card>
      <el-table :data="allRoles" border style="width: 100%">
        <el-table-column
          :label="$t('message.role.index')"
          type="index"
          width="120"
        >
        </el-table-column>
        <el-table-column :label="$t('message.role.name')" prop="title">
        </el-table-column>
        <el-table-column :label="$t('message.role.desc')" prop="describe">
        </el-table-column>
        <el-table-column
          :label="$t('message.role.action')"
          prop="action"
          width="260"
          #default="{ row }"
        >
          <el-button
            type="primary"
            size="mini"
            @click="showPush(row)"
            v-permission="['distributePermission']"
          >
            {{ $t('message.role.assignPermissions') }}
          </el-button>
        </el-table-column>
      </el-table>
    </el-card>
    <PushRole v-model="showPushRole" :roleId="roleId"></PushRole>
  </div>
</template>

<script setup>
import { roleList } from '@/api/role'
import { watchLangChange } from '@/utils/i18n'
import { ref } from 'vue'
import PushRole from './components/PushRole.vue'

const allRoles = ref([])
const getRoleList = async () => {
  allRoles.value = await roleList()
}
getRoleList()
watchLangChange(getRoleList)
// 分配权限弹窗
const showPushRole = ref(false)
const roleId = ref('')
const showPush = (row) => {
  roleId.value = row.id
  showPushRole.value = true
}
</script>
